package com.fifth.apartment.others;

import com.fifth.apartment.result.Result;
import com.fifth.apartment.service.SetmealService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * TODO
 *
 * @author Dao
 * @since 2024/7/7
 */
@RestController
@RequestMapping("/admin/setmeal")
@Api(tags ="文件上传管理")
@Slf4j
public class SetmealController {

    @Autowired
    private  SetmealService setmealService;
    @PostMapping("upload")
    @ApiOperation("套餐图片上传")
    public Result upload(MultipartFile imgFile) throws IOException {
        //返回的是图片名字，拼接上七牛云的域名进行显示
        String pic = setmealService.uploadByAliyun(imgFile);

        //返回的是外链地址，可用于直接显示
        //String pic = setmealService.uploadByAliyun(imgFile);
        if(StringUtils.hasLength(pic)){
            return new Result(true , "上传成功" , pic);
        }
        return new Result(false , "上传失败");
    }
}
